#include <rtthread.h>
#include "base.h" 
#include "rtconfig.h"
#include "rtdef.h"

static struct rt_semaphore sem;

void led_thread_entry(void *parameter){
    while (1) {
        rt_sem_take(&sem, RT_WAITING_FOREVER);
        led_toggle(LED0);
        rt_kprintf("LED toggled by signal!\n");
    }
}

void button_thread_entry(void *parameter) {
    while (1) {
        if (key_pressed()) {
            rt_sem_release(&sem);
        }
        rt_thread_mdelay(100);
    }
}
 
int main(void) {
    hardware_init();  // 初始化 LED、按键等硬件

    rt_sem_init(&sem, "btn_sem", 0, RT_IPC_FLAG_FIFO);

    // 创建两个任务
    rt_thread_startup(rt_thread_create("led", led_thread_entry, RT_NULL,
                                        512, 20, 10));
    rt_thread_startup(rt_thread_create("btn", button_thread_entry, RT_NULL,
                                        512, 15, 10));

    return 0;
}